package com.qf.day01;

import java.util.concurrent.*;

/**
 * @author lixu
 */
public class ThreadDemo {

    public static void main(String[] args) throws Exception{
        //1:种写法
        //new MyThread("AA").start();
        //2:
        //new Thread(new MyRunnable(), "AA").start();
        //3: 线程池
/*        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                5,//核心线程数
                10,//最大线程数
                2,//空闲时间
                TimeUnit.SECONDS,//单位
                new ArrayBlockingQueue<Runnable>(10),//等待队列
                Executors.defaultThreadFactory(),//自带工厂
                new ThreadPoolExecutor.AbortPolicy()//拒绝策略
        );*/
        //执行线程
        //threadPoolExecutor.execute(new MyRunnable());
        //4:Callable

        //中间类
        FutureTask futureTask = new FutureTask(new MyCallable());

        new Thread(futureTask,"AA").start();

        System.out.println("返回值： " + futureTask.get());


    }
}
class MyCallable implements Callable<String>{//返回值类型的指定


    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName());
        return "我是Callable";
    }
}

class MyRunnable implements Runnable {


    public void run() {
        System.out.println(Thread.currentThread().getName());
    }
}

class MyThread extends Thread {

    public MyThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());
    }
}
